package org.future.wsdl.data;

import java.util.ArrayList;
import java.util.List;

import javax.xml.namespace.QName;

/**
 * wsdl:portType 中的 wsdl:operation 元素信息
 * @author dycc
 *
 */
public class WsdlOperation {
    
    private String name;
    
    private QName inMsgQName;
    
    private QName inActionQName;
    
    private String inActionVal;
    // for axis1.4
    private String inName;
    
    private QName outMsgQName;
    
    private QName outActionQName;
    
    private String outActionVal;
    // for axis1.4
    private String outName;
    
    private List<WsdlFault> faults = new ArrayList<WsdlFault>();
    
    private List<XElementInner> inParameters = new ArrayList<XElementInner>();
    
    private XElementInner returnType;
    
    private WsdlMessage inWsdlMessage;
    
    private WsdlMessage outWsdlMessage;
    
    private List<WsdlMessage> faultsMessage = new ArrayList<WsdlMessage>();
    
    private WsdlPortType wsdlPortType;
    
    // name
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    // inMsgQName
    public QName getInMsgQName() {
        return inMsgQName;
    }
    public void setInMsgQName(QName inMsgQName) {
        this.inMsgQName = inMsgQName;
    }
    // inActionQName
    public QName getInActionQName() {
        return inActionQName;
    }
    public void setInActionQName(QName inActionQName) {
        this.inActionQName = inActionQName;
    }
    // inActionVal
    public String getInActionVal() {
        return inActionVal;
    }
    public void setInActionVal(String inActionVal) {
        this.inActionVal = inActionVal;
    }
    // inName
    public String getInName() {
        return inName;
    }
    public void setInName(String inName) {
        this.inName = inName;
    }
    // outMsgQName
    public QName getOutMsgQName() {
        return outMsgQName;
    }
    public void setOutMsgQName(QName outMsgQName) {
        this.outMsgQName = outMsgQName;
    }
    // outActionQName
    public QName getOutActionQName() {
        return outActionQName;
    }
    public void setOutActionQName(QName outActionQName) {
        this.outActionQName = outActionQName;
    }
    // outActionVal
    public String getOutActionVal() {
        return outActionVal;
    }
    public void setOutActionVal(String outActionVal) {
        this.outActionVal = outActionVal;
    }
    // outName
    public String getOutName() {
        return outName;
    }
    public void setOutName(String outName) {
        this.outName = outName;
    }
    // faults
    public List<WsdlFault> getFaults() {
        return faults;
    }
    public void setFaults(List<WsdlFault> faults) {
        this.faults = faults;
    }
    // inParameter
    public List<XElementInner> getInParameters() {
        return inParameters;
    }
    public void setInParameters(List<XElementInner> inParameters) {
        this.inParameters = inParameters;
    }
    // returnType
    public XElementInner getReturnType() {
        return returnType;
    }
    public void setReturnType(XElementInner returnType) {
        this.returnType = returnType;
    }
    // inWsdlMessage
    public WsdlMessage getInWsdlMessage() {
        return inWsdlMessage;
    }
    public void setInWsdlMessage(WsdlMessage inWsdlMessage) {
        this.inWsdlMessage = inWsdlMessage;
    }
    // outWsdlMessage
    public WsdlMessage getOutWsdlMessage() {
        return outWsdlMessage;
    }
    public void setOutWsdlMessage(WsdlMessage outWsdlMessage) {
        this.outWsdlMessage = outWsdlMessage;
    }
    // faultsMessage
    public List<WsdlMessage> getFaultsMessage() {
        return faultsMessage;
    }
    public void setFaultsMessage(List<WsdlMessage> faultsMessage) {
        this.faultsMessage = faultsMessage;
    }
    // wsdlPortType
    public WsdlPortType getWsdlPortType() {
        return wsdlPortType;
    }
    public void setWsdlPortType(WsdlPortType wsdlPortType) {
        this.wsdlPortType = wsdlPortType;
    }
    
    /**
     * toString
     */
    public String toString(){
       StringBuffer sb = new StringBuffer();
       sb.append("<wsdl:operation name=\"" + name + "\">");
       sb.append("\n");
       // add wsdl:input
       if(inMsgQName != null){
           sb.append("<wsdl:input message=\"" + inMsgQName.getPrefix() + ":" + inMsgQName.getLocalPart() + "\"");
           if(inActionQName != null){
               sb.append(" " + inActionQName.getPrefix() + ":" + inActionQName.getLocalPart() + "=\"" + inActionVal + "\"");
           }else if(inName != null){
               sb.append(" name=\"" + inName + "\"");
           }
           sb.append(" />");
           sb.append("\n");
       }
       // add wsdl:output
       if(outMsgQName != null){
           sb.append("<wsdl:output message=\"" + outMsgQName.getPrefix() + ":" + outMsgQName.getLocalPart() + "\"");
           if(outActionQName != null){
               sb.append(" " + outActionQName.getPrefix() + ":" + outActionQName.getLocalPart() + "=\"" + outActionVal + "\"");
           }else if(outName != null){
               sb.append(" name=\"" + outName + "\"");
           }
           sb.append(" />");
           sb.append("\n");
       }
       // add wsdl:fault
       for(int i=0;i<faults.size();i++){
           sb.append(faults.get(i));
           sb.append("\n");
       }
       // end
       sb.append("</wsdl:operation>");
       return sb.toString();
    }
}
